package com.xianzhiOA.service.impl;/**
 * Created by Administrator on 2017/4/27.
 */

import com.xianzhiOA.bean.XzAttendanceStateRecord;
import com.xianzhiOA.dao.XzAttendanceStateRecordMapper;
import com.xianzhiOA.service.XzAttendanceStateRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 出勤状态记录的Service的实现
 *
 * @author 王诗博
 * @create 2017-04-27 10:55
 **/
@Service("XzAttendanceStateRecordService")
public class XzAttendanceStateRecordServiceImpl implements XzAttendanceStateRecordService {
    @Autowired
     private XzAttendanceStateRecordMapper AttendanceStateRecordMapper;

    //根据员工工号和年份和月份查询考勤状态记录
    @Override
    public XzAttendanceStateRecord selectByEmpNoAndYearAndMonth(int empNo,String years,String months) {
        Map<String,Object> map=new HashMap<>();
        map.put("empNo",empNo);
        map.put("years",years);
        map.put("months",months);
        XzAttendanceStateRecord  xzAttendanceStateRecord=AttendanceStateRecordMapper.selectByEmpNoAndYearAndMonth(map);
        return xzAttendanceStateRecord;
    }
    //根据考勤状态表的ID与选定的日期修改选定日期的出勤状态
    @Override
    public int updateByAttendanceStateRecordIdAndDays(long attendanceStateRecordId,String days,String state) {
        Map<String,Object> map=new HashMap<>();
        map.put("attendanceStateRecordId",attendanceStateRecordId);
        map.put("days",days);
        map.put("state",state);
        return AttendanceStateRecordMapper.updateByAttendanceStateRecordIdAndDays(map);
    }

    //通过传来的对象获取数组
    @Override
    public List getArray(XzAttendanceStateRecord xzAttendanceStateRecord) {
        //从xzAttendanceStateRecord取值
        int oneInt=0;
        int twoInt=0;
        int threeInt=0;
        int fourInt=0;
        int fiveInt=0;
        int sixInt=0;
        int sevenInt=0;
        int eightInt=0;
        int nineInt=0;
        int tenInt=0;
        int elevenInt=0;
        int twelveInt=0;
        int thirteenInt=0;
        int fourteenInt=0;
        int fifteenInt=0;
        int sixteenInt=0;
        int seventeenInt=0;
        int eighteenInt=0;
        int nineteenInt=0;
        int twentyInt=0;
        int twentyOneInt=0;
        int twentyTwoInt=0;
        int twentyThreeInt=0;
        int twentyFourInt=0;
        int twentyFiveInt=0;
        int twentySixInt=0;
        int twentySevenInt=0;
        int twentyEightInt=0;
        int twentyNineInt=0;
        int thirtyInt=0;
        int thirtyOneInt=0;

        if(xzAttendanceStateRecord != null) {
            if (xzAttendanceStateRecord.getOne() != null && xzAttendanceStateRecord.getOne() != "") {
                oneInt = Integer.parseInt(xzAttendanceStateRecord.getOne());
            }
            if (xzAttendanceStateRecord.getTwo() != null && xzAttendanceStateRecord.getTwo() != "") {
                twoInt = Integer.parseInt(xzAttendanceStateRecord.getTwo());
            }
            if (xzAttendanceStateRecord.getThree() != null && xzAttendanceStateRecord.getThree() != "") {
                threeInt = Integer.parseInt(xzAttendanceStateRecord.getThree());
            }
            if (xzAttendanceStateRecord.getFour() != null && xzAttendanceStateRecord.getFour() != "") {
                fourInt = Integer.parseInt(xzAttendanceStateRecord.getFour());
            }
            if (xzAttendanceStateRecord.getFive() != null && xzAttendanceStateRecord.getFive() != "") {
                fiveInt = Integer.parseInt(xzAttendanceStateRecord.getFive());
            }
            if (xzAttendanceStateRecord.getSix() != null && xzAttendanceStateRecord.getSix() != "") {
                sixInt = Integer.parseInt(xzAttendanceStateRecord.getSix());
            }
            if (xzAttendanceStateRecord.getSeven() != null && xzAttendanceStateRecord.getSeven() != "") {
                sevenInt = Integer.parseInt(xzAttendanceStateRecord.getSeven());
            }
            if (xzAttendanceStateRecord.getEight() != null && xzAttendanceStateRecord.getEight() != "") {
                eightInt = Integer.parseInt(xzAttendanceStateRecord.getEight());
            }
            if (xzAttendanceStateRecord.getNine() != null && xzAttendanceStateRecord.getNine() != "") {
                nineInt = Integer.parseInt(xzAttendanceStateRecord.getNine());
            }
            if (xzAttendanceStateRecord.getTen() != null && xzAttendanceStateRecord.getTen() != "") {
                tenInt = Integer.parseInt(xzAttendanceStateRecord.getTen());
            }
            if (xzAttendanceStateRecord.getEleven() != null && xzAttendanceStateRecord.getEleven() != "") {
                elevenInt = Integer.parseInt(xzAttendanceStateRecord.getEleven());
            }
            if (xzAttendanceStateRecord.getTwelve() != null && xzAttendanceStateRecord.getTwelve() != "") {
                twelveInt = Integer.parseInt(xzAttendanceStateRecord.getTwelve());
            }
            if (xzAttendanceStateRecord.getThirteen() != null && xzAttendanceStateRecord.getThirteen() != "") {
                thirteenInt = Integer.parseInt(xzAttendanceStateRecord.getThirteen());
            }
            if (xzAttendanceStateRecord.getFourteen() != null && xzAttendanceStateRecord.getFourteen() != "") {
                fourteenInt = Integer.parseInt(xzAttendanceStateRecord.getFourteen());
            }
            if (xzAttendanceStateRecord.getFifteen() != null && xzAttendanceStateRecord.getFifteen() != "") {
                fifteenInt = Integer.parseInt(xzAttendanceStateRecord.getFifteen());
            }
            if (xzAttendanceStateRecord.getSixteen() != null && xzAttendanceStateRecord.getSixteen() != "") {
                sixteenInt = Integer.parseInt(xzAttendanceStateRecord.getSixteen());
            }
            if (xzAttendanceStateRecord.getSeventeen() != null && xzAttendanceStateRecord.getSeventeen() != "") {
                seventeenInt = Integer.parseInt(xzAttendanceStateRecord.getSeventeen());
            }
            if (xzAttendanceStateRecord.getEighteen() != null && xzAttendanceStateRecord.getEighteen() != "") {
                eighteenInt = Integer.parseInt(xzAttendanceStateRecord.getEighteen());
            }
            if (xzAttendanceStateRecord.getNineteen() != null && xzAttendanceStateRecord.getNineteen() != "") {
                nineteenInt = Integer.parseInt(xzAttendanceStateRecord.getNineteen());
            }
            if (xzAttendanceStateRecord.getTwenty() != null && xzAttendanceStateRecord.getTwenty() != "") {
                twentyInt = Integer.parseInt(xzAttendanceStateRecord.getTwenty());
            }
            if (xzAttendanceStateRecord.getTwentyOne() != null && xzAttendanceStateRecord.getTwentyOne() != "") {
                twentyOneInt = Integer.parseInt(xzAttendanceStateRecord.getTwentyOne());
            }
            if (xzAttendanceStateRecord.getTwentyTwo() != null && xzAttendanceStateRecord.getTwentyTwo() != "") {
                twentyTwoInt = Integer.parseInt(xzAttendanceStateRecord.getTwentyTwo());
            }
            if (xzAttendanceStateRecord.getTwentyThree() != null && xzAttendanceStateRecord.getTwentyThree() != "") {
                twentyThreeInt = Integer.parseInt(xzAttendanceStateRecord.getTwentyThree());
            }
            if (xzAttendanceStateRecord.getTwentyFour() != null && xzAttendanceStateRecord.getTwentyFour() != "") {
                twentyFourInt = Integer.parseInt(xzAttendanceStateRecord.getTwentyFour());
            }
            if (xzAttendanceStateRecord.getTwentyFive() != null && xzAttendanceStateRecord.getTwentyFive() != "") {
                twentyFiveInt = Integer.parseInt(xzAttendanceStateRecord.getTwentyFive());
            }
            if (xzAttendanceStateRecord.getTwentySix() != null && xzAttendanceStateRecord.getTwentySix() != "") {
                twentySixInt = Integer.parseInt(xzAttendanceStateRecord.getTwentySix());
            }
            if (xzAttendanceStateRecord.getTwentySeven() != null && xzAttendanceStateRecord.getTwentySeven() != "") {
                twentySevenInt = Integer.parseInt(xzAttendanceStateRecord.getTwentySeven());
            }
            if (xzAttendanceStateRecord.getTwentyEight() != null && xzAttendanceStateRecord.getTwentyEight() != "") {
                twentyEightInt = Integer.parseInt(xzAttendanceStateRecord.getTwentyEight());
            }
            if (xzAttendanceStateRecord.getTwentyNine() != null && xzAttendanceStateRecord.getTwentyNine() != "") {
                twentyNineInt = Integer.parseInt(xzAttendanceStateRecord.getTwentyNine());
            }
            if (xzAttendanceStateRecord.getThirty() != null && xzAttendanceStateRecord.getThirty() != "") {
                thirtyInt = Integer.parseInt(xzAttendanceStateRecord.getThirty());
            }
            if (xzAttendanceStateRecord.getThirtyOne() != null && xzAttendanceStateRecord.getThirtyOne() != "") {
                thirtyOneInt = Integer.parseInt(xzAttendanceStateRecord.getThirtyOne());
            }
        }
        List Arry=new ArrayList();
        Arry.add(0);
        if(oneInt != 0)Arry.add(oneInt);
        if(twoInt != 0)Arry.add(twoInt);
        if(threeInt != 0)Arry.add(threeInt);
        if(fourInt != 0)Arry.add(fourInt);
        if(fiveInt != 0)Arry.add(fiveInt);
        if(sixInt !=0)Arry.add(sixInt);
        if(sevenInt !=0)Arry.add(sevenInt);
        if(eightInt !=0)Arry.add(eightInt);
        if(nineInt !=0)Arry.add(nineInt);
        if(tenInt !=0)Arry.add(tenInt);
        if(elevenInt !=0)Arry.add(elevenInt);
        if(twelveInt !=0)Arry.add(twelveInt);
        if(thirteenInt !=0)Arry.add(thirteenInt);
        if(fourteenInt !=0)Arry.add(fourteenInt);
        if(fifteenInt !=0) Arry.add(fifteenInt);
        if(sixteenInt !=0)Arry.add(sixteenInt);
        if(seventeenInt !=0)Arry.add(seventeenInt);
        if(eighteenInt !=0)Arry.add(eighteenInt);
        if(nineteenInt !=0)Arry.add(nineteenInt);
        if(twentyInt !=0)Arry.add(twentyInt);
        if(twentyOneInt !=0)Arry.add(twentyOneInt);
        if(twentyTwoInt !=0)Arry.add(twentyTwoInt);
        if(twentyThreeInt !=0)Arry.add(twentyThreeInt);
        if(twentyFourInt !=0)Arry.add(twentyFourInt);
        if(twentyFiveInt !=0)Arry.add(twentyFiveInt);
        if(twentySixInt !=0)Arry.add(twentySixInt);
        if(twentySevenInt !=0)Arry.add(twentySevenInt);
        if(twentyEightInt !=0)Arry.add(twentyEightInt);
        if(twentyNineInt !=0)Arry.add(twentyNineInt);
        if(thirtyInt !=0)Arry.add(thirtyInt);
        if(thirtyOneInt !=0)Arry.add(thirtyOneInt);

        return  Arry;
    }

    //根据年查询集合
    @Override
    public List selAllByYears(String years,int empNo) {
        Map<String,Object> map=new HashMap<>();
        map.put("years",years);
        map.put("empNo",empNo);
        List<XzAttendanceStateRecord>  list=  AttendanceStateRecordMapper.selAllByYears(map);

        ArrayList listMonthStateOne=new ArrayList();
        ArrayList listMonthStateTwo=new ArrayList();
        ArrayList listMonthStateThree=new ArrayList();
        ArrayList listMonthStateFour=new ArrayList();
        ArrayList listMonthStateFive=new ArrayList();
        for(int i=0;i<list.size();i++){
            int stateone=0;
            int statetwo=0;
            int statethree=0;
            int statefour=0;
            int statefive=0;

            for(int j=1;j<32;j++){
                String daysValue=null;
                if(j==1 && list.get(i).getOne() != null){
                    daysValue = list.get(i).getOne();
                }
                else if(j==2 && list.get(i).getTwo() !=null){
                    daysValue = list.get(i).getTwo();
                }
                else if(j==3 && list.get(i).getThree() !=null){
                    daysValue = list.get(i).getThree();
                }
                else if(j==4 && list.get(i).getFour() !=null){
                    daysValue = list.get(i).getFour();
                }
                else if(j==5 && list.get(i).getFive() !=null){
                    daysValue = list.get(i).getFive();
                }
                else if(j==6 && list.get(i).getSix() !=null){
                    daysValue = list.get(i).getSix();
                }
                else if(j==7 && list.get(i).getSeven() !=null){
                    daysValue = list.get(i).getSeven();
                }
                else if(j==8 && list.get(i).getEight() !=null){
                    daysValue = list.get(i).getEight();
                }
                else if(j==9 && list.get(i).getNine() !=null){
                    daysValue = list.get(i).getNine();
                }
                else if(j==10 && list.get(i).getTen() !=null){
                    daysValue = list.get(i).getTen();
                }
                else if(j==11 && list.get(i).getEleven() !=null){
                    daysValue = list.get(i).getEleven();
                }
                else if(j==12 && list.get(i).getTwelve() !=null){
                    daysValue = list.get(i).getTwelve();
                }
                else if(j==13 && list.get(i).getThirteen() !=null){
                    daysValue = list.get(i).getThirteen();
                }
                else if(j==14 && list.get(i).getFourteen() !=null){
                    daysValue = list.get(i).getFourteen();
                }
                else if(j==15 && list.get(i).getFifteen() !=null){
                    daysValue = list.get(i).getFifteen();
                }
                else if(j==16 && list.get(i).getSixteen() !=null){
                    daysValue = list.get(i).getSixteen();
                }
                else if(j==17 && list.get(i).getSeventeen() !=null){
                    daysValue = list.get(i).getSeventeen();
                }
                else if(j==18 && list.get(i).getEighteen() !=null){
                    daysValue = list.get(i).getEighteen();
                }
                else if(j==19 && list.get(i).getNineteen() !=null){
                    daysValue = list.get(i).getNineteen();
                }
                else if(j==20 && list.get(i).getTwenty() !=null){
                    daysValue = list.get(i).getTwenty();
                }
                else if(j==21 && list.get(i).getTwentyOne() !=null){
                    daysValue = list.get(i).getTwentyOne();
                }
                else if(j==22 && list.get(i).getTwentyTwo() !=null){
                    daysValue = list.get(i).getTwentyTwo();
                }
                else if(j==23 && list.get(i).getTwentyThree() !=null){
                    daysValue = list.get(i).getTwentyThree();
                }
                else if(j==24 && list.get(i).getTwentyFour() !=null){
                    daysValue = list.get(i).getTwentyFour();
                }
                else if(j==25 && list.get(i).getTwentyFive() !=null){
                    daysValue = list.get(i).getTwentyFive();
                }
                else if(j==26 && list.get(i).getTwentySix() !=null){
                    daysValue = list.get(i).getTwentySix();
                }
                else if(j==27 && list.get(i).getTwentySeven() !=null){
                    daysValue = list.get(i).getTwentySeven();
                }
                else if(j==28 && list.get(i).getTwentyEight() !=null){
                    daysValue = list.get(i).getTwentyEight();
                }
                else if(j==29 && list.get(i).getTwentyNine() !=null){
                    daysValue = list.get(i).getTwentyNine();
                }
                else if(j==30 && list.get(i).getThirty() !=null){
                    daysValue = list.get(i).getThirty();
                }
                else if(j==31 && list.get(i).getThirtyOne() !=null){
                    daysValue = list.get(i).getThirtyOne();
                }
                if (daysValue!=null){
                    try {
                        if(daysValue.equals("1")) {
                            stateone=stateone+1;
                        }
                        if(daysValue.equals("2")) {
                            statetwo=statetwo+1;
                        }
                        if(daysValue.equals("3")){
                            statethree=statethree+1;
                        }
                        if(daysValue.equals("4")){
                            statefour=statefour+1;
                        }
                        if(daysValue.equals("5")){
                            statefive=statefive+1;
                        }
                    } catch (Exception e) {
                        System.out.println("e:"+e.toString());
                        e.printStackTrace();
                    }
                }
            }

            listMonthStateOne.add(stateone);
            listMonthStateTwo.add(statetwo);
            listMonthStateThree.add(statethree);
            listMonthStateFour.add(statefour);
            listMonthStateFive.add(statefive);
          //  System.out.println(i+"月：stateone："+stateone+",statetwo:"+statetwo+",statethree:"+statethree+",statefour:"+statefour+",statefive:"+statefive);
        }

        List listYearState=new ArrayList();
        listYearState.add(listMonthStateOne);
        listYearState.add(listMonthStateTwo);
        listYearState.add(listMonthStateThree);
        listYearState.add(listMonthStateFour);
        listYearState.add(listMonthStateFive);

        return listYearState;
    }

    //用poi往数据库中添加数据
    @Override
    public int insertAttendanceStateRecord(int empNo,String days,String state) {
        Map<String,Object> map=new HashMap<>();
        map.put("empNo",empNo);
        map.put("days",days);
        map.put("state",state);
        return AttendanceStateRecordMapper.insertAttendanceStateRecord(map);
    }
}
